package at.fhooe.mc.android.shiftalarmclock;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class Settings extends Activity implements OnClickListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);
		super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		Button add = (Button) findViewById(R.id.button_add);
		add.setOnClickListener(this);
		Button del = (Button) findViewById(R.id.button_del);
		del.setOnClickListener(this);

	}

	@Override
	public void onClick(View _v) {
		switch (_v.getId()) {
		case R.id.button_add: {
			Intent i = new Intent(this, SettingsTier.class);
			startActivity(i);
			Log.i("AlarmClock", "Button add alarm pressed");
		}
			break;
		case R.id.button_del: {
			int size = MainActivity.list.size() - 1;
			if (size >= 0) {
				// delete listMain
				int x = Integer.parseInt(MainActivity.list.get(size)
						.getHowOften());
				for (int i = 0; i < x; i++) {
					int y = (MainActivity.listMain.size()) - 1;
					MainActivity.listMain.remove(y);
				}
				// delete list
				MainActivity.list.remove(size);
				Log.i("AlarmClock", "Button del pressed");
				ListView lv = (ListView) findViewById(R.id.listViewSettings);
				lv.invalidateViews();
			}
		}
			break;
		}
	}

	@Override
	protected void onResume() {
		super.onResume();

		// List
		@SuppressWarnings("rawtypes")
		ArrayAdapter adapter = new ArrayAdapterSettings(this,
				android.R.layout.activity_list_item, MainActivity.list);
		ListView lv = (ListView) findViewById(R.id.listViewSettings);

		lv.setAdapter(adapter);

	}
}